package com.example.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @Author: hualao
 * @Version: 0.0.1V
 * @Date: 2019/1/9
 * @Description: 消费消息
 **/
@Component
public class KafkaConsumer {
    /**
     * @Author: hualao
     * @Date:   2019/1/9 11:25
     * @Description: topics中填写在服务器上创建的topic即可
    **/
    @KafkaListener(topics = {"test"})
    public void consumer(ConsumerRecord<?,?> record){
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if(kafkaMessage.isPresent()){
            System.out.println(kafkaMessage.get());
        }
    }
}
